package com.ycfmedical.bed.ui;

import java.util.ArrayList;
import java.util.List;

import com.ycfmedical.bed.R;
import com.ycfmedical.bed.base.BaseMenuActivity;
import com.ycfmedical.bed.ui.fragment.HealthChildFragment;
import com.ycfmedical.bed.ui.fragment.HealthFoodFragment;
import com.ycfmedical.bed.ui.fragment.HealthRegimenFragment;
import com.ycfmedical.bed.utils.ResourceUtil;

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.base.XFragmentAdapter;
import cn.droidlover.xdroidmvp.router.Router;

/**
 * 健康头条页面 Created by Egoist on 2017/2/9.
 */

public class HealthNewActivity extends BaseMenuActivity
{
    @BindView(R.id.health_tabs)
    TabLayout tabLayout;
    
    @BindView(R.id.health_viewpager)
    ViewPager viewPager;

    private String[] titles = {ResourceUtil.getContext().getString(R.string.health_tab_food), ResourceUtil.getContext().getString(R.string.health_tab_regimen), ResourceUtil.getContext().getString(R.string.health_tab_child)};

    List<Fragment> fragmentList = new ArrayList<>();

    XFragmentAdapter mAdapter;

    @Override
    public void initData(Bundle savedInstanceState)
    {
        initViewPager();
    }

    private void initViewPager() {

        fragmentList.clear();
        fragmentList.add(HealthFoodFragment.newInstance());
        fragmentList.add(HealthRegimenFragment.newInstance());
        fragmentList.add(HealthChildFragment.newInstance());
        if (mAdapter == null)
        {
            mAdapter = new XFragmentAdapter(getSupportFragmentManager(), fragmentList, titles);
        }
        viewPager.setAdapter(mAdapter);
        viewPager.setOffscreenPageLimit(1);

        tabLayout.setupWithViewPager(viewPager);
    }

    // 修改Toolbar标题
    @Override
    protected void initToolbar()
    {
        super.initToolbar();
        getToolbarTitle().setText(ResourceUtil.getContext().getString(R.string.health_headnews));
    }


    @Override
    public int getLayoutId()
    {
        return R.layout.activity_health;
    }

    @Override
    public Object newP() {
        return null;
    }

    public static void launch(Activity activity)
    {
        Router.newIntent(activity).to(HealthNewActivity.class).launch();
    }
}
